package com.music.controller;

import com.music.pojo.Lyric;
import com.music.service.LyricService;

import com.laoxuai.beans.annotation.Autowired;
import com.laoxuai.beans.annotation.Controller;
import com.laoxuai.ibatis.util.PageInfo;
import com.laoxuai.web.mvc.annotation.RequestMapping;
import com.laoxuai.web.mvc.annotation.ResponseBody;
import com.music.util.Result;

import java.util.List;

@Controller
@RequestMapping("/lyric")
public class LyricController {

    @Autowired
    private LyricService lyricServiceImpl;

    /***
     * 新增
     * @param lyric
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Result insert(Lyric lyric) {
        int result = lyricServiceImpl.insert(lyric);
        return Result.success("增加成功",result);
    }

    /***
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Result delete(Integer id) {
        int result = lyricServiceImpl.delete(id);
        if(result==-1){
            return Result.failed("歌词id不能为空",result);
        }else {
            return Result.success("删除成功",result);
        }
    }

    /***
     * 修改
     * @param lyric
     * @param id
     * @return
     */
    @RequestMapping(value="/update")
    @ResponseBody
    public Result update(Integer id, Lyric lyric) {
        lyric.setId(id);
        int result = lyricServiceImpl.update(lyric);
        if(result==1){
            return Result.failed("歌词不存在");
        }else {
            return Result.success("修改成功",result);
        }
    }

    /***
     * 主键查询
     * @param id
     * @return
     */
    @RequestMapping("/get")
    @ResponseBody
    public Result getByPrimaryKey(Integer id) {
        Lyric lyric = lyricServiceImpl.getByPrimaryKey(id);
        return Result.success("查询成功", lyric);
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Result page(Lyric lyric, int page, int size) {
        PageInfo<Lyric> pageInfo = lyricServiceImpl.listPageInfo(lyric, page, size);
        return Result.success("查询成功", pageInfo);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Result list(Lyric lyric, int page, int size) {
        List<Lyric> list = lyricServiceImpl.listPage(lyric, page, size);
        return Result.success("查询成功", list);
    }
}